package call_handler;

/**
 * GQ.
 * No need to declare abstract here.
 * @author ryan
 *
 */
public 
//abstract 
class Employee {
    private Call currentCall;
    protected Rank rank;

    public Employee(int level) {
	rank = Rank.getRankFromLevel(level);
    }

    public void receiveCall(Call call) {
	this.currentCall = call;
    }

    public void callCompleted() {
	if (currentCall != null) {
	    currentCall.disconnect();

	    currentCall = null;
	}
	/**
	 * GQ.
	 */
	assignNewCall();
    }

    public boolean assignNewCall() {
	if (!isFree()) {
	    return false;
	}
	return CallHandler.getInstance().assignCall(this);
    }

    public void escalateAndReassign() {
	if (currentCall != null) {
	    currentCall.incrementRank();
	    CallHandler.getInstance().dispatchCall(currentCall);
	    currentCall = null;
	}

	assignNewCall();
    }

    public boolean isFree() {
	return currentCall == null;
    }

    public Rank getRank() {
	return rank;
    }
    
}